package com.example.hjt_java_web_homework2.domain.model;

import javax.persistence.Entity;
import javax.persistence.Table;
import java.math.BigDecimal;

/**
 * @author 洪钧韬
 * @date 31/10/2025
 * @description
 */
@Entity
@Table(name = "electric_meters")
public class ElectricMeter extends Device {
    private BigDecimal currentPower;
    private BigDecimal totalEnergy;
    private BigDecimal voltage;

    public ElectricMeter() {}

    public ElectricMeter(String name, String location, String deviceId) {
        super(name, location, deviceId);
        this.currentPower = BigDecimal.ZERO;
        this.totalEnergy = BigDecimal.ZERO;
        this.voltage = new BigDecimal("220.0");
    }

    // 业务方法
    public void recordConsumption(BigDecimal power, BigDecimal energy) {
        this.currentPower = power;
        this.totalEnergy = this.totalEnergy.add(energy);
    }

    // Getters and Setters
    public BigDecimal getCurrentPower() { return currentPower; }
    public void setCurrentPower(BigDecimal currentPower) { this.currentPower = currentPower; }
    public BigDecimal getTotalEnergy() { return totalEnergy; }
    public void setTotalEnergy(BigDecimal totalEnergy) { this.totalEnergy = totalEnergy; }
    public BigDecimal getVoltage() { return voltage; }
    public void setVoltage(BigDecimal voltage) { this.voltage = voltage; }
}
